# -*- coding;utf-8 -*-
"""
File name : CaoliaoQRcode.py.PY
Program IDE : PyCharm
Create file time: 2024/4/15 11:08
File Create By Author : 朱清闯
"""
import requests
import urllib.parse
import qrcode
from PIL import Image


def get_qrcode_and_store_local(url, file_path):
    try:
        # 定义要生成二维码的内容
        data = url

        # 创建QRCode对象
        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_H,
            box_size=10,
            border=4,
        )

        # 将数据添加到QRCode对象中
        qr.add_data(data)
        qr.make(fit=True)

        # 生成QRCode图像
        img = qr.make_image(fill_color="black", back_color="white")

        # 添加Logo到二维码
        # logo = Image.open("logo.png")
        # img.paste(logo, (50, 50))

        # 保存生成的二维码图像
        img.save(file_path)

        # 显示生成的二维码图像
        # img.show()
        return True
    except Exception as e:
        print('local qrcode Exception:', e)
        return False


